#############################################################################
# Copyright (c) 2009 Dmitry Grushin <dgrushin@gmail.com>.
#
# This file is part of clupower (cluster power manager utility)
#
# Clupower is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Clupower is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Clupower.  If not, see <http://www.gnu.org/licenses/>.
#
# Contributors:
#    Dmitry Grushin <dgrushin@gmail.com> - initial API and implementation
#############################################################################

require 'commands'
require 'set'
require 'monitor'
require 'cputil'

class PMDecision
  def initialize
    @nodes_on = []
    @nodes_sleep = []
    @jobs_unlock = []
  end

  attr_accessor :nodes_on, :nodes_sleep, :jobs_unlock
end

class PMA
  def PMA.get_desc
    raise NotImplementedError.new("#{self.class.name}")
  end

  # Makes power management decision considering the list
  # of sleeping node ids.
  # Returns the list of nodes to switch on and off. Does not
  # change nodes list.
  def manage(sleep_nodes, node_wait_list)
    raise NotImplementedError.new("#{self.class.name}")
  end

  def PMA.get_subclasses
    PMA.load_all
    arr = (ObjectSpace.enum_for(:each_object, class << self; self;
        end).to_a - [self]).collect{|c| [c.to_s, c]}
    hres={}; arr.each { |k,v| hres[k]=v }
    return hres
  end

  private
  
  def PMA.load_all
    Dir.glob(File.join(File.dirname(__FILE__), 'algo/*.rb')).each {|f| require f }
  end
end
